﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Tilver.Coder.Core
{
    /// <summary>
    /// 数据库基类
    /// </summary>
    [Serializable]
    public class CoderDataBase : CoderObjectBase
    {
        private string _nameSpace;
        /// <summary>
        /// 命名空间
        /// </summary>
        public string NameSpace
        {
            get
            {
                if (string.IsNullOrEmpty(_nameSpace))
                {
                    _nameSpace = this.DataBase.Project.NameSpace +
                        (string.IsNullOrEmpty(this.DataBase.CodeName) ? string.Empty : "." + this.DataBase.CodeName);
                }
                return _nameSpace;
                //return string.IsNullOrEmpty(_nameSpace) ? (this.DataBase.CodeName + (string.IsNullOrEmpty(Owner) ? string.Empty : "." + Owner)) : _nameSpace;
            }
            set { _nameSpace = value; }
        }
        /// <summary>
        /// 所属项目
        /// </summary>
        [XmlIgnore]
        public CoderProject Project { get; set; }

        /// <summary>
        /// 数据库驱动类型
        /// </summary>
        public DataProviderTypeEnum DataProviderType { get; set; }

        /// <summary>
        /// 连接字符串
        /// </summary>
        public string ConnectionString { get; set; }

        /// <summary>
        /// 表集合
        /// </summary>
        public List<CoderTable> Tables { get; set; }

        /// <summary>
        /// 视图集合
        /// </summary>
        public List<CoderView> Views { get; set; }

        /// <summary>
        /// 命令集合
        /// </summary>
        public List<CoderCommand> Commands { get; set; }

        /// <summary>
        /// 是否从数据库加载，对于已保存的项目，不需要从数据库加载
        /// </summary>
        public bool IsLoad { get; set; }

        /// <summary>
        /// 构造方法
        /// </summary>
        public CoderDataBase()
        {
            base.DataBase = this;
            IsLoad = true;
            Tables = new List<CoderTable>();
            Views = new List<CoderView>();
            Commands = new List<CoderCommand>();
        }
    }
}
